﻿@inject IStringLocalizer<EditFormAlignment> Localizer

<ValidateForm Model="@Model">
    <EditorForm TModel="Foo" ItemsPerRow="2" RowType="RowType.Inline" LabelAlign="Alignment.Right">
        <FieldItems>
            <EditorItem @bind-Field="@context.Hobby" Items="@Hobbys" />
        </FieldItems>
        <Buttons>
            <div class="text-end">
                <Button ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" Text="@Localizer["SubButtonText"]" />
            </div>
        </Buttons>
    </EditorForm>
</ValidateForm>

@code {
    /// <summary>
    /// Foo 类为Demo测试用，如有需要请自行下载源码查阅
    /// Foo class is used for Demo test, please download the source code if necessary
    /// https://gitee.com/LongbowEnterprise/BootstrapBlazor/blob/main/src/BootstrapBlazor.Shared/Data/Foo.cs
    /// </summary>
    [NotNull]
    private Foo? Model { get; set; }

    [NotNull]
    private IEnumerable<SelectedItem>? Hobbys { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<Foo>? FooLocalizer { get; set; }

    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Hobbys = Foo.GenerateHobbys(FooLocalizer);
        Model = new Foo()
        {
            Name = Localizer["TestName"],
            Count = 1,
            Address = Localizer["TestAddr"],
            DateTime = new DateTime(1997, 12, 05),
            Education = EnumEducation.Middle
        };
    }
}
